package pearson.automation.forms.upload;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import framework.BaseForm;
import framework.elements.Button;
import framework.elements.ElementList;
import framework.elements.TextBox;

public class UploadVideoForm extends BaseForm {
    
    private static TextBox file  = new TextBox(By.name("mediaFile"), "File");
    private static Button upload = new Button(By.name("btnSubmit"), "Upload");
    private static Button cancel = new Button(By.linkText("Cancel"), "Cancel");
    
    private static ElementList uploadedList = new ElementList(By.xpath("//fieldset/div[contains(@class, 'upload-item')]/div/h5"),  "Uploaded items");
    
    public UploadVideoForm() {
    super(upload.getLocator(), "Upload video form");
    }
    
    public void setFile(String filePath) {
        file.type(filePath);
    }

    public UploadDetailsForm clickUpload() {
        upload.clickAndWait();
        return new UploadDetailsForm();
    }
    
    public Object[] getRecentlyAddedSection() {
        ArrayList<String> recentlyAdded = new ArrayList<String>();
        List<WebElement> list = uploadedList.getListElements();
        Collections.reverse(list);
        for (WebElement element: list) {
            recentlyAdded.add(element.getText());
        }
        return recentlyAdded.toArray();
    }
}
